﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EFFC.Net.Data.Base;

namespace EFFC.Net.Parameters
{
    public enum ModeType
    {
        FixLength,
        Comma
    }

    [Serializable]
    public class TxtSpec : ParametersStd
    {
        public TxtSpec()
        {
            AddPElement("File_Path");
            AddPElement("Encoding");
            AddPElement("SplitComm");
            AddPElement("StartRow", typeof(IntStd));
            AddPElement("FixLength", typeof(int));
            AddPElement("Mode", typeof(ModeType));
            AddPElement("ProcessMaxRow", typeof(IntStd));
            AddPElement("ColumnsSpec", typeof(Dictionary<string, TxtColSpec>));
        }

        /// <summary>
        /// 文件路徑（含文件名），必填
        /// </summary>
        public string File_Path
        {
            get
            {
                return GetValue<string>("File_Path");
            }
            set
            {
                _p["File_Path"].Value = value;
            }
        }
        /// <summary>
        /// 文件編碼，無則視為default，機器本地語言環境
        /// </summary>
        public string Encoding
        {
            get
            {
                return GetValue<string>("Encoding");
            }
            set
            {
                _p["Encoding"].Value = value;
            }
        }
        /// <summary>
        /// 分隔符（與FixLength二選一）
        /// </summary>
        public string SplitComm
        {
            get
            {
                return GetValue<string>("SplitComm");
            }
            set
            {
                _p["SplitComm"].Value = value;
            }
        }
        /// <summary>
        /// 起始行，無則視為0
        /// </summary>
        public IntStd StartRow
        {
            get
            {
                return GetValue<IntStd>("StartRow");
            }
            set
            {
                if (value == null)
                {
                    _p["StartRow"].Value = 0;
                }
                else
                {
                    _p["StartRow"].Value = value;
                }
            }
        }
        /// <summary>
        /// 固定行長度（與SplitComm二選一）
        /// </summary>
        public int FixLength
        {
            get
            {
                return GetValue<int>("FixLength");
            }
            set
            {
                _p["FixLength"].Value = value;
            }
        }
        /// <summary>
        /// 讀取模式，是FixLength還是Com碼方式，必填
        /// </summary>
        public ModeType Mode
        {
            get
            {
                return GetValue<ModeType>("Mode");
            }
            set
            {
                _p["Mode"].Value = value;
            }
        }
        /// <summary>
        /// 最大一次處理的行數，無則視為整個文檔
        /// </summary>
        public IntStd ProcessMaxRow
        {
            get
            {
                return GetValue<IntStd>("ProcessMaxRow");
            }
            set
            {
                _p["ProcessMaxRow"].Value = value;
            }
        }
        /// <summary>
        /// 欄位規格描述 Dictionary＜ColumnName,DictionaryStd＞類型
        /// </summary>
        public Dictionary<string, TxtColSpec> ColumnsSpec
        {
            get
            {
                return GetValue<Dictionary<string, TxtColSpec>>("ColumnsSpec");
            }
            set
            {
                _p["ColumnsSpec"].Value = value;
            }
        }
    }
}
